import {
    validate
} from '../../../utils/validate.js';
import {
    axios
} from '../../../utils/ajax.js';

Page({
    data: {},

    confirm(e) {
        console.log(e.detail.value.tel)
        let tel = e.detail.value.tel;
        const telReg = /^1(3|4|5|7|8)\d{9}$/;
        if (tel == '') {
            wx.showToast({
                title: '请输入手机号',
                icon: 'none'
            })
            return false
        }
        if (!telReg.test(tel)) {
            wx.showToast({
                title: '手机号格式不正确',
                icon: 'none'
            })
            return false;
        }
        wx.showModal({
            title: '您将添加以下用户为您的推荐人',
            content: tel,
            confirmColor: '#C8431A',
            success: res => {
                if (res.confirm) {
                    axios({
                        url: '/user/recommend',
                        data:{
                          tel: tel
                        }
                    }).then(res => {
                        if (res.data.result == 1) {
                            wx.showToast({
                                title: '添加成功！',
                                icon: 'none'
                            })
                            setTimeout(() => {
                                wx.navigateBack()
                            }, 800)
                        }
                    })
                }
            }
        })
    }
})